/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the Elastic License;
 * you may not use this file except in compliance with the Elastic License.
 */

package org.elasticsearch.xpack.sql.plugin;

import org.elasticsearch.action.support.nodes.BaseNodeRequest;
import org.elasticsearch.action.support.nodes.BaseNodesRequest;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;

import java.io.IOException;

/**
 * Request to gather usage statistics
 */
public class SqlStatsRequest extends BaseNodesRequest<SqlStatsRequest> {
    
    private boolean includeStats;
    
    public SqlStatsRequest() {
    }
    
    public boolean includeStats() {
        return includeStats;
    }

    public void includeStats(boolean includeStats) {
        this.includeStats = includeStats;
    }
    
    @Override
    public void readFrom(StreamInput in) throws IOException {
        super.readFrom(in);
        includeStats = in.readBoolean();
    }

    @Override
    public void writeTo(StreamOutput out) throws IOException {
        super.writeTo(out);
        out.writeBoolean(includeStats);
    }
    
    @Override
    public String toString() {
        return "sql_stats";
    }
    
    static class NodeStatsRequest extends BaseNodeRequest {
        boolean includeStats;
        
        NodeStatsRequest() {}

        NodeStatsRequest(SqlStatsRequest request) {
            includeStats = request.includeStats();
        }
        
        public boolean includeStats() {
            return includeStats;
        }

        @Override
        public void readFrom(StreamInput in) throws IOException {
            super.readFrom(in);
            includeStats = in.readBoolean();
        }

        @Override
        public void writeTo(StreamOutput out) throws IOException {
            super.writeTo(out);
            out.writeBoolean(includeStats);
        }
    }
}
